<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<script>
$(document).ready(function(){
	
	
	registerMenuActions();
});
function registerMenuActions()
{
	$(".action").each(function(){
		$(this).unbind("click");
		$(this).bind("click",function(){
			_loadScreenFor($(this).data('action'));
			
		});

		});
}
function registerGridActions()
{
	$(".for-edit").each(function(){
		$(this).unbind("click");
		$(this).bind("click",function(){
			console.log("Binding event for---");
				console.log($(this).data('action'));
			_loadScreenFor($(this).data('action'));
			
		});

		});
}

	var actionsList={};
	var actionsListIndex=0;
	

	function _loadScreenFor(url){
		console.log(url);
		
		 $('#mainContentBody').fadeOut('slow');
		 $("#mainContentBody").load(url,function(){
				
				$('#mainContentBody').fadeIn('slow');
				 performFormatting();
				 registerMenuActions();
			});
		 actionsList[actionsListIndex]=url;
		 $('._customeBox').remove();
		
		
	 }

	 function _doCommon(url){
			
		 /*$('#mainContentBody').hide('fast');
		 $("#mainContentBody").load(url);
		 $('#mainContentBody').show('fast');
		 actionsList[actionsListIndex]=url;*/
		 
		//alert(actionsList[actionsListIndex]+"/"+url);
		if("add"==url)
			$("#mainContentBody").load(actionsList[actionsListIndex]+"/"+url);
		
		performFormatting();
	 }
	 var _currDetailId='';
	 function showObjectDetaisl(url)
	 {
			var formData ={};
			//formData["id"]=id;
			var params={url:url,success:showBox,data:formData,type:"GET",dataType:"html"};
			doAjax(params);
	 }
	 
	 //TODO:there is common logic of _loadScreenFor in this method. try to maintain them in generic way;
	 function editObject(id, type)
	 {
		 $('#mainContentBody').fadeOut('slow');
		
			var formData ={};
			formData[type+".Id"]=id;
			formData["id"]=id;
			$("#mainContentBody").load("edit",formData,function(){
				
				$('#mainContentBody').fadeIn('slow');
				performFormatting();
			});
			
	 }
	 function showBox(result)
	 {
		 $('#'+_currDetailId).remove();
		 var _box= $( "#_boxContainer" ).clone();
		 $(_box).append(result)
		 	.attr('id',_currDetailId)
		 	.draggable({scroll: true })
		 	.addClass('_customeBox')
		  	.css('left',400)   
		 	.css('top',230)
		 	.find(".close").on('click',function(){$(_box).remove();});
		 $('body').append(_box);
		 $(_box).fadeIn('fast');
		 
	 }
	 
	 function showError(result)
	 {
		 $('#'+_currDetailId).remove();
		 var _box= $( "#_boxContainer" ).clone();
		 $(_box).append(result)
		 	.attr('id',_currDetailId)
		 	.draggable({scroll: true })
		 	.addClass('_customeBox')
		  	.css('left',400)   
		 	.css('top',230)
		 	.find(".close").on('click',function(){$(_box).remove();});
		 $('body').append(_box);
		 $(_box).fadeIn('fast');
		 
		 
	 }
	 
	 function _loadContent(url,formObject)
	 {
	 	//$('.amount').inputmask('remove');
	 		$("#breadcrumbs-one li a").removeClass('current');
	 		$(this).addClass('current');
	 		
	 		jQuery.ajaxSettings.traditional = true;
	 	
	 		var formData = $("#"+formObject).serializeObject();
	 		//formData.rateCards=assignedRate;
	 		console.log("loading form with data----"+formData["financial.financialProductId"]);
	 		var params={url:url,success:_showContent,data:formData,type:"POST",dataType:"html"};
	 		doAjax(params);
	 	
	 } 

	 
	 function _showContent(result)
	 {
	 	
	  	$('#window-content-holder').empty();
	  	$('#window-content-holder').append(result);
	  	$('#window-content-holder').slideDown('slow');
	  	
	  	performFormatting();
		
	 }
	 
	 function performFormatting()
	 {
		 $(".number").inputmask("integer");
		  //$(".date").inputmask("dd/mm/yyyy");
		  $(".phone").inputmask("999-9999-999");
		  $(".amount").inputmask('decimal');
		  $(".decimal").inputmask('decimal');
		  $(".currency").inputmask('decimal');
		  //$(".alpha").inputmask('a',{repeat:30, defaults:{placeholder: ""}});
		  $(".date").datepicker();
		  $("select").chosen({width: "auto"});
		  
	 }
	
</script>